package servlet;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;
import service.GoodsService;
import service.TypeService;


import java.io.IOException;
import java.lang.reflect.Type;

@WebServlet(name="goodsListServlet",value = "/goodsListServlet")
public class goodsListServlet extends HttpServlet {
    private GoodsService gService = new GoodsService();
    private TypeService tService = new TypeService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id=0;
        if (request.getParameter("type")!=null){
            id=Integer.parseInt(request.getParameter("typeid"));
        }
        int pageNumber = 1;
        if (request.getParameter("pageNumber")!=null){
            try {
                pageNumber=Integer.parseInt(request.getParameter("pageNumber"));
            }
            catch (Exception e){

            }
        }
        Type t=null;
        if(id!=0)
        {
            t= (Type) tService.selectTypeNameByID(id);
        }
        request.setAttribute("t",t);
        if (pageNumber<=0)
            pageNumber=1;
        request.setAttribute("id",String.valueOf(id));
        request.getRequestDispatcher("/goods_list.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
